package com.thread.BlockingQueue;

import java.util.Random;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

public class JUC_LinkedBlockingQueueTest {
    static BlockingQueue<String> queue = new LinkedBlockingQueue<>();

    static Random r = new Random();

    public static void main(String[] args) {
        new Thread(()->{

            for(;;){
                try {
                    queue.put("a"+r.nextInt(100));
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        },"p1").start();

        for(int i=0;i<10;i++){
            new Thread(()->{
                for(;;){
                    try {
                        String take = queue.take();
                        System.out.println("get "+take);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }).start();
        }
    }
}
